<?php
	class product
	{	
		function show_product()
		{
			$data = new database();		
			$sql="select * from tblproduct";
			$data->SetQuery($sql);
			$table = $data->LoadAllRow();
			$data->disconnect();
			return $table;	
		}
		function show_product_by_date($date)
		{
			$data = new database();		
			$sql="select * from tblproduct,tblproductVote where tblproduct.productID = tblproductVote.productID and tblproductVote.voteTime =".$date;
			$data->SetQuery($sql);
			$table = $data->LoadAllRow();
			$data->disconnect();
			return $table;	
		}
		function show_product_by_id($productID)
		{
			$data = new database();		
			$sql="select * from tblproduct, tblproductVote where tblproduct.productID = tblproductVote.productID and tblproduct.productID=".$productID;
			//echo $sql;
			$data->SetQuery($sql);
			$table = $data->LoadOneRow();
			$data->disconnect();
			return $table;	
		}
		
		function update($productID,$productName,$productImg=NULL)
		{
			if($productImg!=NULL)
			$sql ="UPDATE tblproduct 
				   SET productName ='{$productName}',proImg='{$productImg}'
				   WHERE productID = {$productID}";
			else
			$sql ="UPDATE tblproduct 
				   SET productName ='{$productName}'
				   WHERE productID = {$productID}";
			echo $sql;
			$data = new database();
			$data->SetQuery($sql);
			$data->Query();
			$data->disconnect();
		}
		
		function delete($productID)
		{	
			$data = new database();		
		
			$sql="DELETE FROM tblproduct WHERE productID = $productID ";
			//echo $sql;
			$data->SetQuery($sql);
			$data->Query();
		}
	
	
	}
?>